package com.taiyuan.tongcheng.adapter;

import java.util.ArrayList;
import java.util.List;

import org.kymjs.kjframe.ui.ViewInject;

import android.app.ListActivity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.taiyuan.tongcheng.bean.OrderCancelReason;
import com.tytc56.user.R;

public class OrderCancelAdapter extends BaseAdapter {
	private LayoutInflater layoutInflater;
	private Context context;
	//整车取消原因
	public static final  String[] CARGO_ORDER_CANCEL_NAME = new String[] {
			"司机距离太远，不愿等待", 
			"同成配送无法提供服务",
			"无人抢单，响应缓慢",
			"订单信息有误，需要重新下单",
			"计划有变，暂不用车",
			"其他原因"
			};
	public static final int[] CARGO_ORDER_CANCEL_ID=new int[]{1,2,3,4,5,60};
	//搬家取消
	public static final  String[] MOVING_ORDER_CANCEL_NAME = new String[] {
		"司机距离太远，不愿等待", 
		"同成配送无法提供服务",
		"无人抢单，响应缓慢",
		"订单信息有误，需要重新下单",
		"计划有变，暂不用车",
		"其他原因"
		};
        public static final int[] MOVING_ORDER_CANCEL_ID=new int[]{1,2,3,4,5,60};
	
	//取消原因
    private List<OrderCancelReason> reasonList=new ArrayList<OrderCancelReason>();
	private int selectPosition=666;
	public static  int CANCEL_ADAPTER_CARGO=1;
	public static  int CANCEL_ADAPTER_MOVING=2;

	public OrderCancelAdapter(Context context,int CancelAdapterFlag) {
		this.context = context;
		reasonList.clear();
		if(CancelAdapterFlag==CANCEL_ADAPTER_CARGO){
			for (int i = 0; i < CARGO_ORDER_CANCEL_NAME.length; i++) {
				OrderCancelReason  reason =new OrderCancelReason();
				reason.setReasonId(CARGO_ORDER_CANCEL_ID[i]);
				reason.setReasonName(CARGO_ORDER_CANCEL_NAME[i]);
				reasonList.add(reason);
			}
		}else if(CancelAdapterFlag==CANCEL_ADAPTER_MOVING){
			for (int i = 0; i < MOVING_ORDER_CANCEL_NAME.length; i++) {
				OrderCancelReason  reason =new OrderCancelReason();
				reason.setReasonId(MOVING_ORDER_CANCEL_ID[i]);
				reason.setReasonName(MOVING_ORDER_CANCEL_NAME[i]);
				reasonList.add(reason);
			}
		}
		
		this.layoutInflater = LayoutInflater.from(context);
	}

	
	
	public OrderCancelReason  getSelectPostion(){
		if(selectPosition==666){
			return null;
		}else{
			return reasonList.get(selectPosition);
		}
	}
	public void setSlectPositon(int postion) {
		
		 if(postion != selectPosition){
		      this.selectPosition = postion;
		     notifyDataSetChanged();
		     }
	}

	public int getCount() {
		return reasonList.size();
	}

	public Object getItem(int position) {
		return reasonList.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ZuJian zuJian = null;
		if (convertView == null) {
			zuJian = new ZuJian();
			convertView = layoutInflater.inflate(R.layout.listview_order_cancel,
					null);
			zuJian.cancelOrderRL=(RelativeLayout)convertView.findViewById(R.id.rl_order_cancel_item);
			zuJian.cancelReason=(TextView)convertView.findViewById(R.id.tv_order_cancel_reason);
			zuJian.cancelStateIcon=(ImageView)convertView.findViewById(R.id.img_order_cancel);
			convertView.setTag(zuJian);
		} else {
			zuJian = (ZuJian) convertView.getTag();
		}

		zuJian.cancelReason.setText(reasonList.get(position).getReasonName());
		if (position == selectPosition) {
			zuJian.cancelOrderRL.setBackgroundResource(R.drawable.order_cancel_bg_green);
			zuJian.cancelStateIcon.setVisibility(View.VISIBLE);
		} else {
			zuJian.cancelOrderRL.setBackgroundResource(R.drawable.order_cancel_bg_white);
			zuJian.cancelStateIcon.setVisibility(View.GONE);
		}
		return convertView;
	}

	public final class ZuJian {
		public RelativeLayout  cancelOrderRL;
		public TextView cancelReason;
		public ImageView cancelStateIcon;
	}

}